package com.lz.football.module.ladderMatch.item
{
	import com.common.utils.Reflection;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.FriendEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.friend.vo.FriendInfoVo;
	import com.liangzhong.model.ladderMatch.vo.RankVo;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	/**
	 * 排名item 
	 * @author Administrator
	 * 
	 */	
	public class RankingItem extends Sprite implements IComponent
	{
		private var symbolSkin		:MovieClip;//皮肤
		/**
		 *积分 
		 */
		private var _integral:TextField;
		/**
		 *名次 
		 */
		private var _rangingLv:TextField;
		/**
		 * 球员名字 
		 */
		private var _playerName:TextField;
		/**
		 *效果 
		 */
		private var _effect:MovieClip;
		/**
		 *俱乐部ID 
		 */
		private var _cid:int;
		
		
		
		public function RankingItem()
		{
			super();
//			initUI();
		}
		
		public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.football.stadium.rankingItem");
			this.addChild(symbolSkin);
			_integral = symbolSkin._integral;
			_rangingLv= symbolSkin._rangingLv;
			_playerName = symbolSkin._playerName;
			_effect = symbolSkin._effect;
			_effect.visible = false;
			setTextColor(0xFFFFFF);
			addEvtListener();
		}
		/**
		 *设置数据 
		 * 
		 */
		public function setData($vo:RankVo):void
		{
			_integral.text = $vo.ladderintegral.toString();
			_rangingLv.text = $vo.levelrank.toString();
			_playerName.text = $vo.name + "";
			_cid = $vo.clubid;
		}
		/**
		 *重置 
		 * 
		 */
		public function reSet():void
		{
			_integral.text = "";
			_rangingLv.text = "";
			_playerName.text = "";
			removeEvtListener();
			_cid = -1;
			setTextColor(0xFFFFFF);
		}
		public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			this.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			this.addEventListener(MouseEvent.CLICK,onClickHandler);
		}
		
		public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			this.removeEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			this.removeEventListener(MouseEvent.CLICK,onClickHandler);
		}
		/**
		 *打开信息面板  
		 * @param event
		 * 
		 */
		protected function onClickHandler(event:MouseEvent):void
		{
			if(_cid == -1)return;
			// TODO Auto-generated method stub
			var fvo :FriendInfoVo = new FriendInfoVo();
//			fvo.name = _playerName.text;
			fvo.friendid = _cid;
			AppData.getInstance().friendManager.tempFriendVo = fvo;
			AppEventDispatcher.getInstance().dispatchEvent(new FriendEvent(FriendEvent.LOOK_UP_FRIEND,{vo:fvo}));
		}
		
		protected function onOutHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			_effect.visible = false;
			setTextColor(0xFFFFFF);
		}
		
		protected function onOverHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			_effect.visible = true;
			setTextColor(0x2468B7);
		}
		/**
		 *设置文本颜色 
		 * 
		 */
		private function setTextColor(value:uint):void
		{
			_integral.textColor = value
			_rangingLv.textColor = value
			_playerName.textColor = value
		}
			
		public function destroyView():void
		{
			removeEvtListener();
			symbolSkin = null;
		}
	}
}